def s(n):
    if n< 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True
def b(i):
    w = {
        'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
        'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
    }
    t = i.split()
    if len(t) != 3:
        print('Wrong input')
        return
    n=int(''.join([str(w[w1]) for w1 in t]))
    if 100 <= n <= 999:
        l=n
        u=n
        while True:
            if s(l):
                print(l)
                break
            if s(u):
                print(u)
                break
            l-= 1
            u+= 1
    else:
        print('Wrong input')
i = input("Введите три слова ")
b(i)